



define(function() {
    
    // console.log(window.env);//env.host

    const host = 'https://cliniques.ewszjk.m.jaeapp.com';

    const getApi = function(method){
        return `${host}/index.php?c=api&m=${method}`;
    };

    const toParam = function(data){
        var re = [];
        for (const key in data) {
            if (data.hasOwnProperty(key)) {
                re.push(`${key}=${data[key]}`);
            }
        }
        return re.join('&');
    }


    return {
        //获取用户信息
        getUserData: function(nick){
            var data={
                mixnick:nick
            }
            return axios.get(getApi('userinfo')+"&"+toParam(data))
        },
        //摇奖
        luckydraw: function(nick){
            const params = new URLSearchParams();
            params.append('mixnick', nick);
            return axios.post(getApi('luckydraw'), params)
        },
        toast(msg){
            if(Tida){
                Tida.toast(msg);
            }else{
                console.info(msg);
            }
        },
        // 分享
        share(){
            return new Promise(function(resolve, reject){
                let title = document.getElementById('WV.Meta.Share.Title');
                let content = document.getElementById('WV.Meta.Share.Text');
                let image = document.getElementById('WV.Meta.Share.Image');

                Tida.share({
                    title: title ? title.attributes.value.value : '',
                    content: content ? content.attributes.value.value : '', //分享的内容
                    url: window.location.href, // 跳转地址，分享的内容跳转的url
                    image: image ? image.attributes.value.value : '',
                }, function(data){
                    resolve(data)
                    // 分享接口调用成功，在手机淘宝下面该回调仅代表API执行成功，非分享成功与否的回调。
                });
            })
        },
        params(){
            let search = window.location.search.replace(/^\?/,'');
            let params = {};
            search.split('&').forEach(p=>{
                let s = p.split('=');
                params[s[0]] = s[1];
            })
            return params;
        }
    };
    
 });